package com.yiren.dbaa.module.practice_set.line.view.dialog;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mapapi.map.BaiduMap;
import com.yiren.backstage.currency.bean.LinePointBean;
import com.yiren.dbaa.R;
import com.yiren.dbaa.view.toast.MessageBox;

/**
 * Describe 百度地图显示前进后退窗口
 *
 * @author WRX
 * @date 2022/11/21
 */
public class BaiduMapInfoWindow {

    private Activity mActivity;
    private OnInfoWindowListener listener;

    public BaiduMapInfoWindow(Activity mActivity, OnInfoWindowListener listener) {
        this.mActivity = mActivity;
        this.listener = listener;
    }

    public View getInfoWindowView(LinePointBean point, int selectPointIndex, BaiduMap mBaiduMaps) {
        View infoView = (ViewGroup) LayoutInflater.from(mActivity).inflate(R.layout.popup_line_point, null);
        ImageView ivPopupClose = (ImageView) infoView.findViewById(R.id.iv_popup_close);
        TextView tvPointName = (TextView) infoView.findViewById(R.id.tv_point_name);
        TextView tvPointRetreat = (TextView) infoView.findViewById(R.id.tv_point_retreat);
        TextView tvPointAdvance = (TextView) infoView.findViewById(R.id.tv_point_advance);
        if (null != point.getProjectInfo() && null != point.getProjectInfo().getName()) {
            tvPointName.setText(selectPointIndex + 1 + "," + point.getProjectInfo().getName());
        }
        //后退两米
        tvPointRetreat.setOnClickListener(v -> {
            if (null == point) {
                MessageBox.show(mActivity, "抱歉，这条线路必须重新采集才能使用移动点位功能");
            } else {
                listener.onPointMove(2, point, selectPointIndex);
            }
            mBaiduMaps.hideInfoWindow();
            listener.onInfoWindowClose();
        });
        //前进两米
        tvPointAdvance.setOnClickListener(v -> {
            if (null == point) {
                MessageBox.show(mActivity, "抱歉，这条线路必须重新采集才能使用移动点位功能");
            } else {
                listener.onPointMove(1, point, selectPointIndex);
            }
            mBaiduMaps.hideInfoWindow();
            listener.onInfoWindowClose();
        });
        //关闭
        ivPopupClose.setOnClickListener(v -> {
            mBaiduMaps.hideInfoWindow();
            listener.onInfoWindowClose();
        });
        return infoView;
    }

    public interface OnInfoWindowListener {

        /**
         * 窗口关闭
         */
        void onInfoWindowClose();

        /**
         * 点位移动
         *
         * @param tzType    1：前进  2：后退
         * @param linePoint
         * @param position
         */
        void onPointMove(int tzType, LinePointBean linePoint, int position);
    }
}
